package com.wyk.springbootdemo.AsyncTest;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Component
@Async
public class AsyncTest {
    public Future<String> test01() throws InterruptedException {
        Long begin =System.currentTimeMillis();
        Thread.sleep(1000L);
        Long end =System.currentTimeMillis();
        System.out.println("任务 1耗时："+(end-begin));
        return  new AsyncResult<String>("任务一");


    }
    public Future<String>  test02()throws  InterruptedException{
        //  获取当前系统时间
        long begin =System.currentTimeMillis();
        Thread.sleep(2000L);

        //  获取当前系统时间
        long end =System.currentTimeMillis();

        System.out.println("任务 2耗时："+(end-begin));
        return  new AsyncResult<String>("任务 2");
    }
}
